<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>跟单费用配置</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script src="js/json2.js" type="text/javascript"></script>
	<script type="text/javascript">
	
	//自定义map功能
	function Map(){
	  this.elements = new Array();
	   //获取MAP元素个数
	   this.size = function() {
	       return this.elements.length;
	   };
	   //判断MAP是否为空
	   this.isEmpty = function() {
	       return (this.elements.length < 1);
	   };
	   //删除MAP所有元素
	   this.clear = function() {
	       this.elements = new Array();
	   };
	   //向MAP中增加元素（key, value)
	   this.put = function(_key, _value) {
	       if(this.containsKey(_key)){
	        this.remove(_key);
	        this.elements.push( {
	           key : _key,
	           value : _value
	        });
	       }else{
	        this.elements.push( {
	           key : _key,
	           value : _value
	        });
	       }  
	   };
	   //删除指定KEY的元素，成功返回True，失败返回False
	   this.remove = function(_key) {
	       var bln = false;
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   this.elements.splice(i, 1);
	                   return true;
	               }
	           }
	       } catch (e) {
	           bln = false;
	       }
	       return bln;
	   };
	   //获取指定KEY的元素值VALUE，失败返回NULL
	   this.get = function(_key) {
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   return this.elements[i].value;
	               }
	           }
	       } catch (e) {
	           return false;
	       }
	       return false;
	   };
	   //判断MAP中是否含有指定KEY的元素
	   this.containsKey = function(_key) {
	       var bln = false;
	       try {
	           for (var i = 0; i < this.elements.length; i++) {
	               if (this.elements[i].key == _key) {
	                   bln = true;
	               }
	           }
	       } catch (e) {
	           bln = false;
	       }
	       return bln;
	   };
	  //获取map的所有values
	  this.values = function() {
	       var arr = new Array();
	       for (var i = 0; i < this.elements.length; i++) {
	           arr.push(this.elements[i].value);
	       }
	       return arr;
	   };
	  //获取map的所有keys
	  this.keys= function() {
	       var arr = new Array();
	       for (var i = 0; i < this.elements.length; i++) {
	           arr.push(this.elements[i].key);
	       }
	       return arr;
	   };
	   //获取数组
	   this.getArray= function(){
	   	var arr = new Array();
	   	for (var i = 0; i < this.elements.length; i++) {
	           arr.push({
		            key : this.elements[i].key,
		            value : this.elements[i].value
		         });
	       }
	       return arr;
	   };
	}
//********************************************	
	var startP = 1;
	var map=new Map();
	var map1=new Map();
	var map2=new Map();
	var weid='';
	var count=1;
	$(document).ready(function() {
		loadNewLifeProductData();
	});
	var exportflag=false;
	
	function querySale(current){
		var agentNo=$.trim($('#saleFeeCode').val());
		var agentName=$.trim($('#saleFeeName').val());
		var bigdate=$('#endDate').val();
		if(bigdate==''){
			bigdate=null;
		}
		var smallDate=$('#startDate').val();
		if(smallDate==''){
			smallDate=null;
		}
		loadNewLifeProductData({agentNo:agentNo,agentName:agentName,bigdate:bigdate,smallDate:smallDate,current:current,size:10}) 
	}
	/***共保费用添加*/
	function addCoinFee(obj){
		count=1;
		/**跟单配置代码*/
		var editTr = $(obj).parent('td').parent('tr')[0];
		var agentNo = editTr.childNodes[1].innerHTML;
		var agentName=editTr.childNodes[2].innerHTML;
		var weidConfig=editTr.childNodes[5].innerHTML;
		weid=weidConfig;
		map.put("agentNo",agentNo);
		$('#showAgentCode').html("跟单费用配置代码："+agentNo);
		$('#showAgentName').html("跟单费用配置名称：<input type='text' id='copyaddName' value='"+agentName+"'/>");
		$('#agentCodeHide').val(agentNo);
		$("#copyOrUpdateFlag").val('update');
		copyOrAdd(agentNo);
	}
	function copyAdd(){
		var radioProduct = $("input[name='checkPlan']:checked");
		if(radioProduct.val()!=undefined){
			count=1;
			/**跟单配置代码*/
			var agentNo = radioProduct.parent().parent().children(" td:eq(1)").html();
			var agentName=radioProduct.parent().parent().children(" td:eq(2)").html();
			var weidConfig=radioProduct.parent().parent().children(" td:eq(5)").html();
			weid=weidConfig;
			map.put("agentNo",agentNo);
			$('#showAgentCode').html("跟单费用配置代码："+agentNo);
			$('#showAgentName').html("跟单费用配置名称：<input type='text'  id='copyaddName' value='"+agentName+"'/>");
			$('#agentCodeHide').val(agentNo);
			$("#copyOrUpdateFlag").val('copy');
			copyOrAdd(agentNo)	
		}else{
			$.message("error", "请选择一条费用配置");
		}
	}
	function copyOrAdd(agentNo){
		$.openLoading();
		map.clear();
		var copyOrUpdateFlag=$("#copyOrUpdateFlag").val();
		//查询已配置的三费列表
		$.ajax({
			url : "<%=path%>/nlifeSaleConfig/queryCoins?"+new Date().getTime(),
			type : 'POST',
			async : false,
			dataType:'json',
			data:{
				agentNo:agentNo
			},
			success : function(result) {
				agentNo=result.agentNo;
				var title='';
				var data1='';
				loadPrivilegeBranchSelect();
				if(agentNo!=-1){
					count=agentNo;
					var coins=result.coins;
					for (var i = 0; i <coins.length; i++) {
						addCoinFeeColum (coins[i].seq);
						data1+=map.get("data");
					}
				}else{
					addCoinFeeColum (count);
					data1+=map.get("data");
				}
				$('#addcointTr').html(map.get("title")+data1)
				if(agentNo!=-1){
					for (var i = 0; i <coins.length; i++) {
						addOption(coins[i].seq)
					}
				}else{
					addOption(count)
				}
				//赋值
				if(result.coins&&result.coins.length>0){
					for (var i = 0; i < result.coins.length; i++) {
						if($('#branch'+coins[i].seq)){
							$('#branch'+coins[i].seq).val(coins[i].branch);
							$('#branchshow'+coins[i].seq).val(coins[i].branchName);
						}
						if($('#isAgent'+coins[i].seq)){
							$('#isAgent'+coins[i].seq).val(coins[i].isAgent);
						}
						if($('#productType'+coins[i].seq)){
							$('#productType'+coins[i].seq).val(coins[i].productType);
						}
						if($('#empNo'+coins[i].seq)){
							$('#empNo'+coins[i].seq).val(coins[i].empNo);
						}
						//系统来源
						if($('#sys'+coins[i].seq)){
							$('#sys'+coins[i].seq).val(coins[i].sysSource);
						}
						$('#commRate'+coins[i].seq).val(coins[i].commRate);
						$('#marketRate'+coins[i].seq).val(coins[i].marketRate);
						$('#businessRate'+coins[i].seq).val(coins[i].businessRate);
					}	
				}
				$('#addCoinFee').OpenDiv();
				$.closeLoading();
			}
		});
	}
	/**下拉框增加选项*/
	function addOption(colum){
		//产品大类
		var productTypeSelect = document.getElementById("productType"+colum);
		if(productTypeSelect!=null){
			productTypeSelect.length=0;
			var productTypes = map.get('prodTypes');
			if(productTypes&&productTypes.length > 0){
				for (var j = 0; j < productTypes.length; j++) {
					var option = new Option();
					option.text = productTypes[j].codeName;
					option.title = productTypes[j].codeName;
					option.value = productTypes[j].code;
					productTypeSelect.add(option);
				}
			}	
		}
		//业务来源
		var isAgentsSelect = document.getElementById("isAgent"+colum);
		if(isAgentsSelect!=null){
			isAgentsSelect.length=0;
			var isAgents = map.get('isAgents');
			if(isAgents&&isAgents.length > 0){
				for (var j = 0; j < isAgents.length; j++) {
					var option = new Option();
					option.text = isAgents[j].codeName;
					option.title = isAgents[j].codeName;
					option.value = isAgents[j].code;
					isAgentsSelect.add(option);
				}
			}	
		}
	}
	function addRow(){
		count++;
		addCoinFeeColum (count);
		var colum1=new Array();
		colum=map.get("colum");
		/* if(colum.length>=81){
			$.message("error","本页面最大增加81条" );
			return;
		} */
		data=$('#addcointTr').html();
		$('#addcointTr').append(map.get("data"));
		addOption(count);
	}
	/**删除*/
	function delSaleFeeConfi(count,obj){
		var editTr = $(obj).parent('td').parent('tr')[0];
		if(count==1){
			$.message("error","第一行数据无法删除" );
			return;
		}
		editTr.remove();
		var colum=new Array();
		var colum1=new Array();
		colum=map.get("colum");
		for (var i = 0; i < colum.length; i++) {
			if(colum[i]!=count){
				colum1.push(colum[i])
			}
		}
		map.put("colum", colum1);
	}
	//加载机构下拉框
	function loadPrivilegeBranchSelect(){
		$.ajax({
				url : "<%=path%>/nlifeSaleConfig/querySelectOption?"+new Date().getTime(),
				type : 'POST',
				async : false,
				dataType:'json',
				success : function(result) {
					if(result){
						map.put('branch',result.depts);
						map.put('isAgents',result.isAgents);
						map.put('prodTypes',result.prodTypes);
					}
				}
		});
	 }
	/**三费保存**/
	function coinFeeConfig(){
		var arr1 = new Array(); 
		map1.clear();
		//获取所有三费id列表
		var colum=new Array()
		colum=map.get("colum");
		//权重和
		var sumProp=0;
		for (var i = 0; i < colum.length; i++) {
			var isEvg=false;
			sumProp=0;
			//机构
			var branchsel=$('#branch'+colum[i]);
			var branch='';
			var flag='';
			/**判断是否已经存在分支机构*/
			var o=new Object();
			//判断是否选择了机构
			if(branchsel){
				branch=branchsel.val();				
				if(branch!=null&&branch!=""&&branch){
					sumProp=sumProp+parseInt(map2.get("prop_0").otherCode);
					branch=$('#branchshow'+colum[i]).val();
					if(branch!='-'){
						var arr_branch = branch.split("-");
						branch = arr_branch[0];
					}
				}else{
					branch=$('#branchshow'+colum[i]).val();
					if(branch==''){
						$.message("error", "序号为"+(colum[i])+"机构不能为空");
						return
					}
				}
				flag+=branch;
				o.branch=branch;
			}
			//产品大类
			var productTypesel=$('#productType'+colum[i]);
			if(productTypesel){
				var productType=productTypesel.val();
				if(productType!=null&&productType!=""&&productType){
					sumProp=sumProp+parseInt(map2.get("prop_2").otherCode);
				}
				flag+=productType
				o.prototype=productType;
			}
			//业务来源
			var isAgentsel=$('#isAgent'+colum[i]);
			if(isAgentsel){
				var isAgent=isAgentsel.val();
				flag+=isAgent;
				o.isAgent=isAgent;
				if(isAgent!=null&&isAgent!=""&&isAgent){
					sumProp=sumProp+parseInt(map2.get("prop_1").otherCode);
				}
				if(isAgent=='DX'){
					isEvg=true;
				}
			}
			//代理人代码/服务代码
			var empNoInp=$('#empNo'+colum[i]);
			if(empNoInp){
				var empNo=empNoInp.val();
				flag+=empNo;
				o.empNo=empNo;
				if(empNo!=null&&empNo!=""&&empNo){
					sumProp=sumProp+parseInt(map2.get("prop_3").otherCode);
				}
				if(isEvg&&empNo!=''&&empNo){
					$.message("error", "序号为"+(colum[i])+"业务来源为电销业务，代理人代码/业务员代码应为空");
					return
				}
			}
			//系统来源
			var sys=$('#sys'+colum[i]);
			if(sys){
				var sysSource=sys.val();
				flag+=sysSource;
				o.sysSource=sysSource;
				if(sysSource!=null&&sysSource!=""&&sysSource){
					sumProp=sumProp+parseInt(map2.get("prop_4").otherCode);
				}
			}
			o.sumProp=sumProp+"";
			if(map1.get(flag)){
				$.message("error", "相同维度信息只能有一条数据");
				return
			}else{
				map1.put(flag,true);
			}
			var commRate=$('#commRate'+colum[i]).val();
			if(commRate==''){
				$.message("error", "序号为"+(colum[i])+"手续费比例不能为空");
				return
			}
			o.commRate=commRate
			var marketRate=$('#marketRate'+colum[i]).val();
			if(marketRate==''){
				$.message("error", "序号为"+(colum[i])+"市场维护费比例不能为空");
				return
			}
			o.marketRate=marketRate;
			var businessRate=$('#businessRate'+colum[i]).val();
			if(businessRate==''){
				$.message("error", "序号"+(colum[i])+"业务绩效比例不能为空");
				return
			}
			o.businessRate=businessRate;
			//判断三费和是否小于100
			var rate=parseFloat(commRate)+parseFloat(businessRate)+parseFloat(marketRate);
			if(rate>=100){
				$.message("error", "序号"+(colum[i])+"三费相加必须小于100");
				return
			}
			o.seq=colum[i]+"";
			arr1.push(o);
		}
		//判断是新增、复制新增
		var copyOrUpdateFlag=$('#copyOrUpdateFlag').val();
		var copyaddName=$("#copyaddName").val();
		if(copyaddName==''){
			$.message("error", "请输入跟单费用配置名称");
			return
		}
		//alert(arr1);
		var arr=JSON.stringify(arr1);
		//alert(arr);
	    var agentNo=$('#agentCodeHide').val();
		$.openLoading();
		$.ajax({
			url : "nlifeSaleConfig/saveCoinFee?"+new Date().getTime(),
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				coinFee:arr,
				agentNo:agentNo,
				copyOrUpdate:copyOrUpdateFlag,
				copyaddName:copyaddName
			},
			success:function(data) {
				 $.closeLoading();
				 if(data.success){
					closeCurrentDIV("addCoinFee");
					$.message("success",data.message);
					loadNewLifeProductData();
				 }else{
					$.message("error", data.message);
				 }
			}
		});
	}
	/**共享包费用添加列处理**/
	function addCoinFeeColum (count1){
		var weids=weid.split(',');
		var trtitle='<tr>';
		var data='<tr>'
		trtitle+='<td>序号</td>'
		data+="<td>"+(count1)+"</td>"
		var title="";
		for (var i = 0; i < weids.length; i++) {
			/**维度选择了机构**/
			if('0'==weids[i]){
				trtitle+="<td>机构</td>";
				data+="<td><input type='hidden' id='branch"+count1+"' ><input style='width:120px;' type='text' id='branchshow"+count1+"' class='input_text' style=' background-color: #ccc;'><input class='input_button_2' type='button' onclick='openDeptDiv(this)' value='请选择' style='width:60px;'></td>"
				title+="机构："+map2.get("prop_0").otherCode;
			}
			/**业务来源*/
			if('1'==weids[i]){
				trtitle+="<td>业务来源</td>";
				data+="<td><select id='isAgent"+count1+"'  onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' style='width:120px;'></select></td>"
				title+="业务来源："+map2.get("prop_1").otherCode;
			}
			/**产品大类**/
			if('2'==weids[i]){
				trtitle+="<td>产品大类</td>";
				data+="<td><select id='productType"+count1+"'  onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' style='width:80px;'></select></td>"
				title+="产品大类："+map2.get("prop_2").otherCode;
			}
			/**代理人代码/服务代码*/
			if('3'==weids[i]){
				trtitle+="<td style='width:130px;'>代理人代码/业务员代码</td>";
				data+="<td><input  type='text' id='empNo"+count1+"' class='input_text' style='width:120px;'></td>"
				title+="代理人/业务员："+map2.get("prop_3").otherCode;
			}	
			/**系统来源/系统来源*/
			if('4'==weids[i]){
				trtitle+="<td>系统来源</td>";
				data+="<td><input  type='text' id='sys"+count1+"'style='width: 75px' class='input_text'></td>"
				title+="系统来源："+map2.get("prop_4").otherCode+"&nbsp;";
			}			
		}
		//手续费比例
		trtitle+="<td>手续费比例</td>";
		data+="<td><input id='commRate"+count1+"'style='width: 75px' class='input_text'  onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'/>%</td>";
		//市场维护费比例 marketPreserveRate
		trtitle+="<td>市场维护费比例</td>";
		data+="<td><input id='marketRate"+count1+"' style='width: 75px'class='input_text' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'/>%</td>";
		//业务绩效比例 businessPerformanceRate
		trtitle+="<td>业务绩效比例</td>";
		data+="<td><input id='businessRate"+count1+"'style='width: 75px' class='input_text' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'/>%</td>";
		data+="<td><a href='javascript:void(0)' onClick='delSaleFeeConfi("+count1+",this);return false'>删除</a></td>";
		data+='</tr>'
		trtitle+="<td>操作</td>";
		trtitle+='</tr>'
		map.put("data", data);
		if(title!=''){
			$('#weid_title').html("权重："+title)
		}
		if(count1==1){
			var colum=new Array()
			colum.push(count1)
			map.put("colum", colum);
		} else{
			var colum=map.get("colum")
			if(!colum){
				colum=new Array()
			}
			colum.push(count1)
			map.put("colum", colum);
		} 
		map.put("title", trtitle);
	}
	function loadNewLifeProductData(param){
		   var jsonDate;
			if(null != param&& null != param.current ){
				var str = "";
				var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
				var startDate = param.smallDate;
				var endDate = param.bigdate;
				if(null != startDate && "" != startDate){
					if(startDate.match(strReg)==null){
						$.message("error", "您输入的定义起期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				if(null != endDate && "" != endDate){
					if(endDate.match(strReg)==null){
						$.message("error", "您输入的定义止期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				jsonDate =param;
			}else{
				jsonDate={current:1,size:10};
			}
			$.openLoading();
			$.ajax({
				url : "nlifeSaleConfig/querySalePageByCriteria?"+new Date().getTime(),
				type : 'POST',
				async : true,
				dataType:'json',
				data:jsonDate,
				success:function(page) {
					 $.closeLoading();
					startP = page.current;
					var firstbutton="<input type='radio' value='' name='checkPlan' class='input_fxk'>";				
					var lastbutton = "<a href='javascript:void(0)' onClick='addCoinFee(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delSaleConfi(this);return false'>删除</a>";
					var tableContent = creatTable2("AGENT_NO,AGENT_NAME,OPERATOR_CODE,INSERT_TIME,WEID_CONFIG@TDH",page,firstbutton,lastbutton);
					var tableObj = $("#gatewayproductTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage(startP,6,page.maxPage,"62");
					var pageDIV = $("#txproductpageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					bindradio();
					var weids=page.map.weids;
					if(weids!=undefined&&weids.length>0){
						for (var i = 0; i < weids.length; i++) {
							map2.put("prop_"+weids[i].code,weids[i]);
						}
					}
				}
			});
		}
	
	function delSaleConfi(obj){
		$.dialog({
			type: "warn",//success,error
			content: "您确定要删除该配置吗？",
			onOk: function() {
				var editTr = $(obj).parent('td').parent('tr')[0];
				var tradProdCode = editTr.childNodes[1].innerHTML;
				$.openLoading();
				$.ajax({
					url : "nlifeSaleConfig/deleteSaleConfig",
					type : 'POST',
					async : true,
					dataType:'json',
					data:{
						agentNo:tradProdCode
					},
					success:function(page) {
						 $.closeLoading();
						 if(page.success){
							$.message("success",page.message );
						}else{
							$.message("error",page.message );
						}
						loadNewLifeProductData(null);
					}
				});
			}
		});
	}
	/**保存费用配置**/
	function saveFeeConfig(){
		var weidConfigs =$('input[name=weidConfig]:checked');
		if(weidConfigs.val()==undefined){
			$.message("error", "请选择费用配置维度");
			return;
		}
		var weiConfig='';
		weidConfigs.each(function(){
			if(weiConfig==''){
				weiConfig= $(this).val();
			}else{
				weiConfig+=","+ $(this).val();
			}	
		})
		/**选择业务员/代理人必须选择业务来源**/
		if(weiConfig.indexOf("3")>=0){
			if(weiConfig.indexOf("1")<0){
				$.message("error", "选择【代理人/业务员】维度时【业务来源】维度必选");
				return;
			}
		}
		var agentNo=$("#agentNo").html();
		var agentName=$.trim($("#agentName").val());
		if(agentName==null||agentName==''){
			$.message("error", "请输入费用配置名称");
			return;
		}
		$.openLoading();
		$.ajax({
			url : "nlifeSaleConfig/saveFeeConfig",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				weidConfig:weiConfig,
				agentNo:agentNo,
				agentName:agentName
			},
			success : function(obj) {
				$.closeLoading();
				if(obj.success){
					closeCurrentDIV('addFeeConfig');
					$('#agentName').val('');
					$.message("success",obj.message );
					loadNewLifeProductData();
				}else{
					$.message("error",obj.message );
				}
			}
		});
	 }
	var weidFlag=false;
	/**保存费用配置结束**/
	function add(){
		$('#agentName').val('');
		$.openLoading();
		$.ajax({
			url : "nlifeSaleConfig/addFeeConfigDiv?"+new Date().getTime(),
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
			},
			success : function(obj) {
				$.closeLoading();
				//加载维度信息
				var weids=obj.weidTypes;
				var weidsCon=''
				if(weids&&!weidFlag){
					for (var i = 0; i < weids.length; i++) {
						weidsCon+='<tr><td  style="text-align: left; padding-left:15px"><input type="checkbox" value="'+weids[i].code+'" name="weidConfig"> '+weids[i].codeName +"</td><td>权重:<input type='text' style='width: 50px' value='"+weids[i].otherCode+"' disabled='disabled'></td>";
						if(i==0){
							weidsCon+="<td colspan='2' rowspan='"+weids.length+"'><span style='margin-left: -5px' class='red'>权重值说明：权重影响跟单费用维度取值优<br/>先级如需调整请联系合作伙伴人员</span></td></tr>";
						}
						weidsCon+="</tr>"
					}
					$('#weidConfigtd').after(weidsCon);
					weidFlag=true;
				}
				$("input[name='weidConfig']").each(function(){
					$(this).attr("checked",false);
				})
				$('#agentNo').html(obj.agentNo);
			    $('#addFeeConfig').OpenDiv();
			}
		});
	}
	//关闭  窗口
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
	function insuranceAdd(){
		var radioProduct = $("input[name='radioProduct']:checked");
		if(radioProduct.val()!=undefined){
			var flag=1;
			if(exportflag){
				flag=2;
			}
			var tradProdCode = radioProduct.parent().parent().children(" td:eq("+flag+")").html();
			window.location.href='<%=basePath%>nlifeProductConfig/newLifeRiskAddReq?tradProdCode='+tradProdCode;
		}else{
			$.message("error", "请选择一个产品");
		}
	}
	/**
	   机构加载
	*/
	var divFlag='';
	function openDeptDiv(obj){
		//加载第一页出单机构
		$("#deptCname_choose").val('');
		$("#deptCode_choose").val('')
		divFlag=obj;
		queryDept(1);
	}
	//加载出单机构信息前，拼接参数
	function queryDept(pageIndex){
		var size = 8;
		var deptName=$("#deptCname_choose").val();
		var deptCode=$("#deptCode_choose").val();
		loadSaleDept({size:size,current:pageIndex,deptName:deptName,deptCode:deptCode});
	}
	//根据传入的参数，加载相应的出单机构
	function loadSaleDept(param){
		$("#BigDiv2").remove();
		$.openLoading();
		$.ajax({
			url : "<%=path%>/nlifeSaleConfig/queryDeptPageByCriteria?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page))return;
	
				var radioObj ="<input class='input_fxk' name='radioDept' type='radio'/>";
				var fieldNames = "DEPT_CODE,DEPT_CNAME";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#deptTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage3(param.current,6,page.maxPage,"69");
				var pageDIV = $("#deptPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				$('#deptDiv').OpenDiv2();
			 	bindradio(); 
			}
		});
	}
	function bindradio(){
		$("input[name='radioDept']").click(function(){
			$("input[name='radioDept']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
	   	});
		$("input[name='checkPlan']").click(function(){
			$("input[name='checkPlan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");

       	});
	}
	//关闭
	function closeDeptDiv (){
		$('#deptDiv').CloseDiv2();
	}
	//选中机构
	function chooseDept(){
		var radioProduct = $("input[name='radioDept']:checked");
		if(radioProduct.val()==undefined){
			$.message("error", "请选择一个机构");
			return 
		}
		var deptCode=radioProduct.parent().parent().children("td:eq(1)").html();
		var deptName=radioProduct.parent().parent().children("td:eq(2)").html();
		$(divFlag).parent().find("input[type='text']").val(deptName);
		$(divFlag).parent().find("input[type='hidden']").val(deptCode);

		closeDeptDiv()
	}
	function vreset (){
		$("#saleFeeCode").val('');
		$("#saleFeeName").val('');
		$('#startDate').val('');
		$('#endDate').val('');
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">新意健险产品管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>意健险跟单费用配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="20%" height="30">跟单配置代码：
								<input name="txt3" id="saleFeeCode" type="text" class="input_text" maxlength="30" value="">
							</td>
							<td width="20%" height="30">跟单配置名称：
								<input name="txt3" id="saleFeeName" type="text" class="input_text" maxlength="100" value="">
							</td>
							<td width="15%" height="30">定义时间：
								<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
							</td>
							<td width="15%" height="30">至
								 <input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
							</td>
							<td style="text-align: center;" colspan="5" width="10%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="querySale(1)" />&nbsp;
							    <input type="button" class="input_button_1" id="searchBtn" value="重置" onClick="vreset()" />
							</td>
						</tr>
						<tr height="30px">
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="100%" height="30">
								<input type="button" class="input_button_2" id="searchBtn" value="新增费用配置" onClick="add()" style='width:100px'/>&nbsp;
								<input type="button" class="input_button_2" id="copyAddBtn" value="复制新增" onClick="copyAdd()" />&nbsp;
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="gatewayproductTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th>选择</th>
								<th>跟单配置代码</th>
								<th>跟单配置名称</th>
								<th>定义人</th>
								<th>定义时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txproductpageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		<!-- 新增费用配置 -->
		<div id="addFeeConfig" style="display:none;width:50%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('addFeeConfig')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td>
				</td>
			</tr>
			<tr>
				<td>
					<table id="addFeeConfigTable"  class="content_table_1">
						<thead>
						</thead>
						<tbody>
							<tr id="weidConfigtd"  >
								<td > 请选择费用配置维度:</td>
								<td colspan="3" style="text-align: left; " ></td>
							</tr>
							<tr>
								<td>跟单配置代码：</td>
								<td id="agentNo"></td>
								<td >配置跟单名称：</td>
								<td><input type="text" id="agentName" /></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="saveFeeConfig()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeCurrentDIV('addFeeConfig')" class="input_button_3"/>
		</div>
	</div>
	<!-- 新增费用配置结束 -->
		<!--跟单费用配置 -->
		<div id="addCoinFee" style="display:none;width:90%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('addCoinFee')"/></td>
						</tr>
					</table>
			</div>
		<div style="width:100%;text-align: center; height: 300px; overflow: scroll;">
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td style="text-align: left;">
					<span style="margin-left: 5px" id="showAgentCode"></span>
					<span style="margin-left: 5px" id="showAgentName"></span>
					<span  id="weid_title" class="red" style="margin-left: 5px"></span>
					<input type="hidden" value="" id="agentCodeHide">
					<input type="hidden" value="" id="copyOrUpdateFlag">
				</td>
			</tr>
			<tr>
				<td>
					<table id="addCoinFeeTable"  class="content_table_1">
						<thead>
						</thead>
		 				<tbody id="addcointTr">
						</tbody>
				 	</table>
				</td>
			</tr>
		</table>
		</div>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="coinFeeConfig()" class="input_button_3"/>
		   <input type="button" value="取消" onclick="closeCurrentDIV('addCoinFee')" class="input_button_3"/>
		   <input type="button" id="addRow" value="增加" onclick="addRow()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		</div>
	</div>
	<!-- begin ------------------------出单机构 DIV 默认隐藏--------------------------->
	<div id="deptDiv" style="display:none;width:80%;">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height: 20px;'>
				<tr>
				<td width="10%"></td>
				<td width="80%" id="interfaceName"></td>
				<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeDeptDiv()"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							机构代码：<input name="txt3"  id="deptCode_choose" class="input_text" />&nbsp;&nbsp;
							机构名称：<input name="txt3" id="deptCname_choose" class="input_text" />
								       <input type="button"  class="input_button_1" value="查询" onClick="queryDept(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:45%">机构代码</th>
			                  <th style="width:50%">机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeDeptDiv()" class="input_button_3"/>
		</div>
	</div>
<!-- end ------------------------出单机构 DIV 默认隐藏--------------------------->	
	
</body>
</html>